/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package inet.controller;

import inet.dao.TimeKeepingsDAO;
import inet.entity.TimeKeepings;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ÂuNgọcThái
 */
@ManagedBean
@SessionScoped
public class TimeKeepController {

    /**
     * Creates a new instance of TimeKeepController
     */
    TimeKeepingsDAO tkDAO = null;
    TimeKeepings tk = null;
    List<TimeKeepings> lstTk = null;

    public TimeKeepController() {
        tk = new TimeKeepings();
        tkDAO = new TimeKeepingsDAO();
        lstTk = new ArrayList<TimeKeepings>();
    }

    public TimeKeepingsDAO getTkDAO() {
        return tkDAO;
    }

    public void setTkDAO(TimeKeepingsDAO tkDAO) {
        this.tkDAO = tkDAO;
    }

    public TimeKeepings getTk() {
        return tk;
    }

    public void setTk(TimeKeepings tk) {
        this.tk = tk;
    }

    public List<TimeKeepings> getLstTk() {
        return lstTk;
    }

    public void setLstTk(List<TimeKeepings> lstTk) {
        this.lstTk = lstTk;
    }

    public List<TimeKeepings> getListTK() {
        if (UserController.empLogin.getRoll() == 0) {
            return tkDAO.getAll();
        } else if (UserController.empLogin.getRoll() == 1) {
            return tkDAO.getAll();
        } else {
            return tkDAO.getAllByID(UserController.empLogin.getEmp_id());
            //return tkDAO.getAll();
        }
    }

    public void editTK(BigDecimal id) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        try {
            facesContext.getCurrentInstance().getExternalContext().redirect("emp/edit/");

        } catch (IOException ex) {
            Logger.getLogger(TimeKeepController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    

    public String chamCong(BigDecimal tkid, String cong) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        tkDAO = new TimeKeepingsDAO();
        if (tkDAO.update(tkid,cong)) {
            facesContext.addMessage("frcamcong", new FacesMessage("Chấm chông thành công" + tk.getCong() + tk.getTk_id() ));
            return "";
        } else {
            facesContext.addMessage("frcamcong", new FacesMessage(tk.getCong() + tk.getTk_id()));
            return "";
        }
    }
    
    public String convertData(int a) {
        String b = null;
        if (a==1) {
            b = "-1";
        } else if (a==2) {
             b = "-0.5";
        } else if (a==3) {
             b = "0";
        } else if (a==4) {
            b = "1";
        } else if (a==5) {
            b = "0.5";
        } else if (a==6) {
            b = "1*";
        } else if (a==7) {
            b = "x";
        }else{
            b = "";
        }
        return b;
    }
    
    
    
}
